package com.zzyl.nursing.service.impl;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.zzyl.nursing.service.IQianFanAiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class QianFanAiServiceImpl implements IQianFanAiService {
    @Value("${qianfan.accessKey}")
    private String accessKey;
    @Value("${qianfan.secretkey}")
    private String secretkey;
    @Value("${qianfan.model}")
    private String model;
    @Override
    public String chatQianFan(String prompt) {
        log.info("与千帆大模型开始对话");
        Qianfan qianfan = new Qianfan(accessKey,secretkey);
        ChatResponse response = qianfan.chatCompletion()
                .addUserMessage(prompt)
                .model(model)
                .responseFormat("json_object")
                .execute();

        return response.getResult();
    }
}
